package com.whq.thrift.api.web.admin.db.admin;

import java.util.Map;

import org.apache.ibatis.jdbc.SqlBuilder;

import com.whq.common.StringUtil;

public class UserInfoSqlProvider {
	public String getSelectRecordSql(Map<String, Object> parameter) {
		SqlBuilder.BEGIN();
		SqlBuilder.SELECT("*");
		SqlBuilder.FROM("t_user_info");
		if (parameter.get("email") != null) {
			SqlBuilder.WHERE("email=#{email}");
		}

		if (parameter.get("status") != null) {
			SqlBuilder.WHERE("status=#{status}");
		}
		

		SqlBuilder.ORDER_BY("email asc");
		return SqlBuilder.SQL() + " limit #{beginIndex}, #{maxCount} ";
	}

	public String getSelectCountSql(Map<String, Object> parameter) {
		SqlBuilder.BEGIN();
		SqlBuilder.SELECT("count(*)");
		SqlBuilder.FROM("t_user_info");

		if ((parameter.get("email") != null) && (StringUtil.isNotBlank(parameter.get("email").toString()))) {
			SqlBuilder.WHERE("email like #{email}");
		}

		if (parameter.get("status") != null) {
			SqlBuilder.WHERE("status=#{status}");
		}

		return SqlBuilder.SQL();
	}

	public String getUpdateSql(UserInfo record) {
		SqlBuilder.BEGIN();
		SqlBuilder.UPDATE("t_user_info");

		if (StringUtil.isNotBlank(record.getStatus()+"")) {
			SqlBuilder.SET("status = #{status}");
		}

		if (record.getUpdateTime() != null) {
			SqlBuilder.SET("update_time=#{updateTime}");
		}

		SqlBuilder.WHERE("email=#{email}");
		return SqlBuilder.SQL();
	}
	
}
